<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				exists:'',
				instIdCache:'con-sale-trade-title9-instId-cache',
				instId:'',
				instName:''
			})
		},
		methods:{
			onInputTotalPrice(val){
				let _that = this
				if(!val){
					_that.$refs.autoform.clear("title9","totalPrice")
				}
			},
			onSelectProject(item){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				if(!formdata.partakeInstId){
					formdata.partakeInstId = _that.instId
					formdata.partakeInstName = _that.instName
				}
			},
			initload(){
				let _that = this
				let arr = [
					_that.om.request(
						'tsysdict/getCombobox',
						{
							code: '41023',
							notInId:_that.exists
						}
					)
				]
				Promise.all(arr).then(res=>{
					_that.$refs.autoform.changeEditor("title9","projectId","data",configSelectData(res[0],'id','dicname'))
					_that.$refs.autoform.initSelectIndex("title9","projectId")
				})
			},
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() { 
				_that.exists = _that.datas.filter((d,i)=>{
					return (i != _that.index)
				}).map(d=>d.projectId).join(",")
				if(e.instId){
					_that.instId = e.instId
					_that.instName = e.instName
				}
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("title9","partakeInstId",{
								"link":'../../public/search/search',
								"linkParam":{
									other:JSON.stringify(),
									url:'tinstitution/getComboTree',
									namefield:'text',
									initload:true,
									cachename:_that.instIdCache
								}
							},null,_that.autoformdata)
							_that.initload()
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key:_that.instIdCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.partakeInstId = d.id
							formdata.partakeInstName = d.text
							uni.removeStorage({
								key:_that.instIdCache
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
